package com.huaxia.controller;

import com.huaxia.pojo.SalesData;
import com.huaxia.service.SalesDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.WebApplicationContext;

import javax.servlet.ServletContext;

/**
 * @author wangli 爱我华夏，爱我中华！
 * @date 2020/04/22 10:26
 */
@RestController
@RequestMapping("/navigation")
public class SalesDataController {

    @Autowired
    private WebApplicationContext webApplicationContext;
    @Autowired
    private SalesDataService salesDataService;


    //获取营销数据
    @GetMapping("/getSalesData")
    public SalesData getSalesData(){
        ServletContext servletContext = webApplicationContext.getServletContext();
        SalesData salesData = (SalesData)servletContext.getAttribute("salesData");
        if(salesData==null){
            salesData = salesDataService.getSalesData();
            servletContext.setAttribute("salesData",salesData);
            return salesData;
        }
        return salesData;
    }
}
